﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace SocialKit.LightRest.Tests.RestUtilityTests
{
    [TestFixture]
    public class ParseQueryStringTests
    {
        string query;
        Dictionary<string, string> dict;


        [SetUp]
        protected void TestSetup()
        {
            query = "b=是的&a=1.0&c=0xCE=";
            dict = new Dictionary<string, string>() { 
            { "b", "是的" },
            { "a", "1.0" },
            { "c", "0xCE=" } 
            };
        }

        #region ParseQueryString Tests

        [Test]
        public void ParseQueryStringNormalTest()
        {
            var result = RestUtility.ParseQueryString(query);

            Assert.AreEqual(3, result.Count());
        }

        [Test]
        public void ParseQueryStringExceptionTest()
        {
            Assert.Throws<ArgumentNullException>(() => RestUtility.ParseQueryString(null));
        }

        [Test]
        public void ParseQueryStringEmptyTest()
        {
            Assert.Throws<ArgumentNullException>(() => RestUtility.ParseQueryString(""));
        }

        [Test]
        public void ParseQueryStringMarkTest()
        {
            var result = RestUtility.ParseQueryString("?");

            Assert.AreEqual(0, result.Count());
        }

        [Test]
        public void ParseQueryStringEqualEndTest()
        {
            var result = RestUtility.ParseQueryString(query);

            Assert.AreEqual(true, result.Last().Value.EndsWith("="));
        }

        [Test]
        public void ParseQueryStringNoKeyTest()
        {
            var result = RestUtility.ParseQueryString("abcde");

            Assert.AreEqual(1, result.Count());
        }

        #endregion
    }
}